//
//  TopMenuBtn.m
//  小团购
//
//  Created by 樊荣海 on 15/1/23.
//  Copyright (c) 2015年 樊荣海. All rights reserved.
//

#import "TopMenuBtn.h"
#define kTitleScale 0.8

@implementation TopMenuBtn

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self == [super initWithFrame:frame]) {
        
        [self setTitleColor:globalTintColor forState:UIControlStateNormal];
        [self.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
        [self setImage:[UIImage imageNamed:@"ic_arrow_down"] forState:UIControlStateNormal];
        self.imageView.contentMode = UIViewContentModeCenter;
        
//        UIImage *img = [UIImage imageNamed:@"separator_topbar_item"];
//        UIImageView *divider = [[UIImageView alloc] init];
//        divider.backgroundColor = [UIColor grayColor];
//        divider.bounds = CGRectMake(0, 0, 0.5, MenuButtonH * 0.5);
//        divider.center = CGPointMake(0.25, MenuButtonH * 0.5);
//        [self addSubview:divider];

        //选中背景
        [self setBackgroundImage:[UIImage resizedImage:@"selected_bg"] forState:UIControlStateSelected];
        
    }
    
    return self;
    
}

- (void)setTitle:(NSString *)title {

    _title = title;
    
    [self setTitle:_title forState:UIControlStateNormal];
}



//宽度写死
- (void)setFrame:(CGRect)frame {
    
    frame.size = CGSizeMake(MenuButtonW, MenuButtonH);
    [super setFrame:frame];
}

- (void)setBounds:(CGRect)bounds {
    
    bounds.size = CGSizeMake(MenuButtonW, MenuButtonH);
    [super setBounds:bounds];
}


- (void)setHighlighted:(BOOL)highlighted {}


- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat h = contentRect.size.height;
    CGFloat w = contentRect.size.width * kTitleScale;
    return CGRectMake(0, 0, w, h);
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat h = contentRect.size.height;
    CGFloat x = contentRect.size.width * kTitleScale;
    CGFloat w = contentRect.size.width - x;
    return CGRectMake(x, 0, w, h);
}

@end
